<?php
//Check for access file
if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
 * Class design course
 */
class Course extends Front_Controller {
    private $ci;

//    function Course() {
    function  __construct() {
       parent::Front_Controller();
    }

    public function index() {
        $this->ci = & get_instance();
        $act = $this->ci->uri->segment(2);

        switch($act) {
            case 'dang-ky':
                $this->addCourse();
                break;
            case 'chi-tiet':
                $this->detailCourse();
                break;
            case 'cap-nhat':
                $this->updateCourse();
                break;
            default:

                break;
        }
    }

    /**
     * @desc Introduce course
     * @return void()
     */
    function addCourse() {
        /*
        Array
        (
        [course_name] => Khóa luyện TOIEC 97
        [course_desc] => Khóa luyện TOIEC 97
        [course_address] => Truong Chinh, Quan Tan Binh
        [course_khaigiang] => 13 / 03 / 2012
        [cboThoiluong] => 1
        [course_tiethoc] => 60
        [course_lichhoc] => 2 - 4 - 6 6:0PM or 3 - 5 - 7 6:0PM or 7 - CN 8:0AM
        [cboHocphi] => 2
        [course_hocphi] =>
        [course_chungchi] => CCA
        [course_doituong] => All
        [course_uudai] => 5 %
        [course_giangvien] => Nguyen Van A
        [course_lienhe] => 8483820912 or 0908123456
        [course_gioihandk] => 35
        [course_songaydkoffline] => 2
        [course_giamhocphi] => 15 %
        [course_thongtinkhac] => Cac ban dk nhanh tay, vi so luong co han
        [submit] => Submit
        )
        */
        if (isset($_POST['submit'])) {

            $parseDate = isset($_POST['course_khaigiang'])?explode('/', $_POST['course_khaigiang']):NULL;
            $start_date = (count($parseDate) > 1)?$parseDate[2] . '-' . $parseDate[1] . '-' . $parseDate[0]: NULL;
            $arrData = array(
                'provider_id' => isset($_POST['provider_id'])?$_POST['provider_id']:1,
                'course_name' => $_POST['course_name'],
                'course_description' => $_POST['course_desc'],
                'create_date' => date('Y-m-d'),
                'start_date' => $start_date,
                'end_date' => isset($_POST['course_ketthuc'])?$_POST['course_ketthuc']:NULL,
                'max_num_learner' => $_POST['course_gioihandk'],
                'address' => $_POST['course_address'],
                'max_day_regrister_offline' => $_POST['course_songaydkoffline'],
                'original_fee' => $_POST['course_uudai'],
                'discount_fee' => $_POST['course_giamhocphi'],
                'entry_requirement' => $_POST['course_chungchi'],
                'registration_approve' => 1,
                'other_info' => $_POST['course_thongtinkhac'],
            );

            $this->ci->load->module_model('blocks.courses_model');
            $result = $this->ci->courses_model->insert($arrData);
            if ($result) {
                //Redirect self
                redirect('/Thiet-lap-khoa-hoc');
            }
        }

        $this->view('course_register');
    }
    //End Index

    /**
     * @desc Chi tiet khoa hoc
     */
    function detailCourse() {

        $arrParam = $this->ci->uri->segment_array();
        $this->ci->load->module_model('blocks.courses_model');
        $arrData = array('userid' => 1, 'course_id' => 1);
        $result = $this->ci->courses_model->getCourseById($arrData);
        $this->add('results', $result);
        $this->view('course_detail_block');
    }

    /**
     * @desc Cap nhat khoa hoc
     */
    function updateCourse() {
        $arrParam = $this->ci->uri->segment_array();
        print_r($arrParam);die;
    }


}